package com.ruoyi.backstage.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.zzw.domain.ServerManage;
import com.ruoyi.zzw.service.TServerManageService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 服务器管理Controller
 * 
 * @author ruoyi
 * @date 2023-12-06
 */
@RestController
@RequestMapping("/backstage/server")
public class BackServerManageController extends BaseController
{
    @Autowired
    private TServerManageService tServerManageService;

    /**
     * 查询服务器管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:server:list')")
    @GetMapping("/list")
    public TableDataInfo list(ServerManage serverManage)
    {
        startPage();
        List<ServerManage> list = tServerManageService.selectTServerManageList(serverManage);
        return getDataTable(list);
    }

    /**
     * 导出服务器管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:server:export')")
    @Log(title = "服务器管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ServerManage serverManage)
    {
        List<ServerManage> list = tServerManageService.selectTServerManageList(serverManage);
        ExcelUtil<ServerManage> util = new ExcelUtil<ServerManage>(ServerManage.class);
        util.exportExcel(response, list, "服务器管理数据");
    }

    /**
     * 获取服务器管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:server:query')")
    @GetMapping(value = "/{cServerid}")
    public AjaxResult getInfo(@PathVariable("cServerid") Long cServerid)
    {
        return success(tServerManageService.selectTServerManageByCServerid(cServerid));
    }

    /**
     * 新增服务器管理
     */
    @PreAuthorize("@ss.hasPermi('system:server:add')")
    @Log(title = "服务器管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ServerManage serverManage)
    {
        return toAjax(tServerManageService.insertTServerManage(serverManage));
    }

    /**
     * 修改服务器管理
     */
    @PreAuthorize("@ss.hasPermi('system:server:edit')")
    @Log(title = "服务器管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ServerManage serverManage)
    {
        return toAjax(tServerManageService.updateTServerManage(serverManage));
    }

    /**
     * 删除服务器管理
     */
    @PreAuthorize("@ss.hasPermi('system:server:remove')")
    @Log(title = "服务器管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{cServerids}")
    public AjaxResult remove(@PathVariable Long[] cServerids)
    {
        return toAjax(tServerManageService.deleteTServerManageByCServerids(cServerids));
    }
}
